<?php
// this is the standard template data
$templateData = array(
                'title' => $this->title,
                'resourceUri' => $this->resourceUri,
                'description' => $this->description,
                'descriptionHelper' => $this->descriptionHelper,
                'options'           => $this->options
        );
?>

<?php
    /*
     * Loads a feed silently
     */
    function loadMyFeed ($url) {
        $entries = array();
        
        // check then feed uri
        if (!Erfurt_Uri::check($url)) {
            return $entries;
        }

        try {
            // this uses 304 http codes to speed up retrieval
            Zend_Feed_Reader::useHttpConditionalGet();

            // try to load the feed from uri
            $feed = Zend_Feed_Reader::import($url);
            
        } catch (Exception $e) {
            // feed import failed
            return $entries;
        }

        // collect entries of the feed
        foreach ($feed as $entry) {
            $date = explode (' ', $entry->getDateModified());
            $date = $date[0];
            $newEntry = array (
                'h4'        => $entry->getTitle(),
                'p' => str_replace('[...]', '', substr(strip_tags($entry->getDescription()), 0, 500)) . '...',
                'date' => $date,
                'a'         => $entry->getLink(),
            );
            $entries[$entry->getLink()] = $newEntry;
        }

        if (count($entries) > 3) {
            $entries = array_slice($entries, 0, 3);
        }
        return $entries;
    }
?>


<?php if ($content = trim($this->partial('lod2/content.phtml', $templateData))): ?>

<div class="maincontent">
    <div class="section">
        <h3><?php echo $this->title ?></h3>

    <?php
        $entries = array ();
        if (isset($this->description['http://lod2.eu/schema/importantFeed'])) {
            $feedUri = $this->description['http://lod2.eu/schema/importantFeed'][0]['value'];
            $entries = loadMyFeed ($feedUri);
        } 
    ?>    
    <?php if (count($entries) > 0): ?>
    <?php foreach($entries as $entry): ?>
        <div class="section-content"><p>
            <a href="<?php echo $entry['a'];?>"><?php echo $entry['date'];?> - <?php echo $entry['h4'];?></a>
                     <?php echo $entry['p'];?> <a href="<?php echo $entry['a'];?>">read</a>
                     </p></div>
     <?php endforeach; ?>
        &nbsp;
     <?php endif; ?>
        
        <div class="section-content">
            <?php echo $content; ?>
        </div>
    </div>
</div>

<?php endif; ?>
